<template>
    <div>
        <el-card>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-input placeholder="请输入单号" v-model="queryInfo.query" clearable @clear="getOrderList">
                        <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
                    </el-input>
                </el-col>
                <el-col :span="4">

                </el-col>
            </el-row>
            <el-row>
                <el-table :data="orderList" border stripe>
                    <el-table-column align="center" type="index" label="序号"></el-table-column>
                    <el-table-column align="center" label="订单编号" prop="id"></el-table-column>
                    <el-table-column align="center" label="用户编号" prop="userId"></el-table-column>
                    <el-table-column align="center" label="订单价格" prop="allPrice"></el-table-column>
                    <el-table-column align="center" label="是否付款" prop="status">
                        <template v-slot="scope">
                            <el-tag type="success" v-if="scope.row.status == '1'">已付款</el-tag>
                            <el-tag type="danger" v-else>未付款</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="下单时间" prop="createTime">
                        <template v-slot="scope">
                            {{scope.row.createTime | dateFormat}}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="操作">
                        <template v-slot="scope">
                            <el-button type="primary" icon="el-icon-edit" size="mini" @click="showBox">编辑</el-button>
                            <el-button type="danger" icon="el-icon-delete" size="mini" @click="removeById(scope.row.id)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <!--分页区-->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="queryInfo.pageNum"
                        :page-sizes="[3, 6, 9, 12]"
                        :page-size="queryInfo.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </el-row>
        </el-card>


    </div>
</template>

<script>
    import {order_delete, order_request} from "../../network/order";

    export default {
        name: "Order",
        data(){
            return{
                queryInfo:{
                    query:'',
                    way:0,
                    pageNum: 1,
                    pageSize: 3
                },
                orderList:[],
                total:0
            }
        },
        created() {
            this.getOrderList()
        },
        methods:{
            getOrderList(){
                order_request(this.queryInfo.query,this.queryInfo.way,this.queryInfo.pageNum,this.queryInfo.pageSize)
                .then(res=>{
                    this.orderList=res.orders.records
                    this.total=res.orders.total
                    console.log(res);
                })
            },
            handleSizeChange(newSize){
                this.queryInfo.pageSize=newSize
                this.getOrderList()
            },
            handleCurrentChange(newPage){
                this.queryInfo.pageNum=newPage
                this.getOrderList()
            },
            removeById(id){
                this.$confirm('此操作将永久删除该分类, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    order_delete(id).then(res=>{
                        console.log(res);
                        if (res.msg==='success'){
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            })
                            this.getOrderList()
                        }
                        else{
                            this.$message.error("删除失败，有商品使用该分类！")
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
            },
            showBox(){

            }
        }
    }
</script>

<style scoped>

</style>